package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Orders;
import com.qf.mapper.OrdersMapper;
import com.qf.service.OrdersService;
import enums.PageSizeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 2019/12/9 0009
 * Administrator
 * 江朝西暮，湖晨南曦
 */
@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper orderMapper;
    @Override
    public PageInfo<Orders> findAll(@RequestParam(defaultValue = "1") Integer pageIndex, Integer pageSize,String str,Integer order_state,String startDate,String endDate) {
        PageHelper.startPage(pageIndex, PageSizeEnum.PAGESIZE.getPagesize());
        Map map= new HashMap();
        map.put("str",str);
        map.put("state",order_state);
        map.put("startDate",startDate);
        map.put("endDate",endDate);
//        调用mapper层方法
        List<Orders> orders = orderMapper.findAll(map);
//        创建pageInfo对象
        PageInfo<Orders> pageInfo=new PageInfo<>(orders);
        return pageInfo;
    }


    @Override
    //    查询所以预约来获得机构名称
    public List<Orders> findAllOrderIns() {
        return orderMapper.selectAll();
    }

    @Transactional
    @Override
    //    添加预约信息
    public Integer addOrder(Orders orders) {
        return orderMapper.insert(orders);
    }

    @Override
    //    根据预约编号查询预约的全部信息
    public Orders findOrderByProId(Integer proId) {
        Orders params=new Orders();
        params.setProId(proId);
        return orderMapper.selectOne(params);

    }

    @Override
    @Transactional
    //    修改预约信息
    public Integer updateOrdersByProId(Orders orders) {
        Orders params=new Orders();
        params.setProId(orders.getProId());
        params.setInsName(orders.getInsName());
        params.setUserName(orders.getUserName());
        params.setOrderDate(orders.getOrderDate());
        params.setUserPhone(orders.getUserPhone());
        params.setOrderAim(orders.getOrderAim());
        params.setOrderResult(orders.getOrderResult());
        params.setOrderState(orders.getOrderState());
        params.setServerUser(orders.getServerUser());
        params.setPic(orders.getPic());
        params.setHandleDate(new Date());
        return orderMapper.updateByPrimaryKey(params);
    }

    @Override
    //  删除预约信息
    @Transactional
    public Integer deleteOrderByProId(Integer proId) {
        return orderMapper.deleteByPrimaryKey(proId);
    }

    @Override
    //  批量删除预约信息
    @Transactional
    public Integer deleteOrderByProIds(int[] proId) {

        return orderMapper.deleteOrderByProIds(proId);
    }

    @Override
        //   根据proId查询所有预约，导出
    public List<Orders> toExcel(int[] proId) {
        return orderMapper.toExcel(proId);
    }


}
